using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Xml;


namespace DAO
{
    public class SqlDataAccessHelper
    {       
        #region ConnectionString
        //private static String connectionString;      
        public static String ConnectionString
        {
            get
            {
                return ReadConnectionString("DataString.xml");
            }
        }
        public static String ReadConnectionString(String file)
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(file);
                XmlElement root = doc.DocumentElement;
                String connectionString = root.InnerText;
                return connectionString;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
        #endregion
        #region ExecuteQuery
        public static DataTable ExecuteQuery(String query)
        {
            DataTable table = new DataTable();

            SqlConnection connect = new SqlConnection(@"Server = THANHTHAO-PC;Database=QLBVCB;Trusted_Connection=True;");
                connect.Open();
               
                    SqlCommand command = connect.CreateCommand();
                    command.CommandType = CommandType.Text;
                    command.CommandText = query;
                    SqlDataAdapter adapter = new SqlDataAdapter();
                    adapter.SelectCommand = command;
                    adapter.Fill(table);
          
                    
                
                    connect.Close();
               

           
            return table;
        }
        #endregion
        #region ExecuteNoneQuery
        public static int ExecuteNoneQuery(String query)
        {
            int n;


            SqlConnection connect = new SqlConnection(@"Server = THANHTHAO-PC;Database=QLBVCB;Trusted_Connection=True;");
                connect.Open();
               
                    SqlCommand command = connect.CreateCommand();
                    command.CommandType = CommandType.Text;
                    command.CommandText = query;
                    n = command.ExecuteNonQuery(); 
                

                
                
                    connect.Close();
                
         
           
            return n;
        }
        #endregion

    }
}
